package wechat.start.wechatstart.entity;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;

import java.util.Map;

/**
 * Created by WuJiXian on 2020/12/4 22:30
 * 所有消息的基类，将公有的抽取定义在这里面比如
 * ToUserName	是	接收方帐号（收到的OpenID）
 * FromUserName	是	开发者微信号
 * CreateTime	是	消息创建时间 （整型）
 * MsgType	是	消息类型，文本为text
 */
@Data
@XStreamAlias("xml")
public class BaseMessage {

    @XStreamAlias("ToUserName")
    private String toUserName;
    @XStreamAlias("FromUserName")
    private String fromUserName;
    @XStreamAlias("CreateTime")
    private String createTime;
    @XStreamAlias("MsgType")
    private String msgType;

    public BaseMessage(Map<String, String> requestMap, String msgType) {
        // 因为收发对象转化了，所以这里收发方一定要颠倒过来
        this.toUserName = requestMap.get("FromUserName");
        this.fromUserName = requestMap.get("ToUserName");
        this.createTime = System.currentTimeMillis() / 1000 + "";
        this.msgType = msgType;
    }

    public BaseMessage() {

    }

}
